package goleetcode

import "sort"

func filterRestaurants(restaurants [][]int, veganFriendly int, maxPrice int, maxDistance int) []int {
	filter := [][]int{}
	for _, r := range restaurants {
		if r[3] <= maxPrice && r[4] <= maxDistance && !(veganFriendly == 1 && r[2] == 0) {
			filter = append(filter, r)
		}
	}
	sort.Slice(filter, func(i, j int) bool {
		return filter[i][1] > filter[j][1] || (filter[i][1] == filter[j][1] && filter[i][0] > filter[j][0]) 
	})
	res := []int{}
	for _, r := range filter {
		res = append(res, r[0])
	}

	return res
}